<template>
  <div>
    <h2>借款列表展示</h2>
    款项名称<input type="text" v-model="state.Bname">
    <select v-model="state.Lid">
            <option v-for="item in list" :value="item.Lid" >每年{{item.Lnum}}%</option>
          </select>
          <input type="button" value="查询" @click="sel">
    <table class="table" border=1>
      <tr>
        <td>借款款项编号</td>
        <td>借款款项名称</td>
        <td>借款最高金额</td>
        <td>借款最高年限</td>
        <td>利息编号</td>
        <td>借款款项简介</td>
        <td>预计每月还款</td>
        <td>操作</td>
      </tr>
      <tr v-for="item in blist">
        <td>{{item.Bid
        }}</td>
        <td>{{item.Bname
        }}</td>
        <td>{{item.
MaxMoney}}</td>
        <td>{{item.MaxYear}}</td>
        <td>{{item.FKT_LxInfo
.Lnum
        }}%</td>
        <td>{{item.Bremark
        }}</td>
        <td>{{((item.
          MaxMoney*(item.FKT_LxInfo
          .Lnum/100)+item.
          MaxMoney)/(item.MaxYear*12)).toFixed(2)}}</td>
        <td><input type="button" value="删除" @click="Delete(item.Bid)">
          <input type="button" value="修改" @click="Upd"></td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import router from '@/router';
import axios from 'axios';
import { reactive, toRefs, onMounted } from 'vue';
let data = reactive({
  state: {
    Bname: '',
    Lid:0
  },
  list: {},
  blist:{},
});
let { state, list ,blist} = toRefs(data);
onMounted(() => {
  GetList();
  BorrowList();
});
function GetList()
  {
    axios({
      url:"http://localhost:61513/api/borrow/GetLxInfoList",
      method:"get",
    })
    .then(res=>{
      console.log(res);
      list.value=res.data.data
    })
    .catch(err=>{
      console.log(err);
    })
  }
  function sel()
  {
    BorrowList();
  }
function BorrowList() 
{
  axios({
    url:"http://localhost:61513/api/borrow/GetBorrowInfoList",
    method:"",
    params:state.value
  })
  .then(res=>{
      console.log(res);
      blist.value=res.data.data
    })
    .catch(err=>{
      console.log(err);
    })
}
function Delete(id:any)
{
  if(confirm("确定要删除吗"))
  {
    axios({
      url:"http://localhost:61513/api/borrow/GetBorrowDel",
      method:"get",
      params:{
        Bid:id
      }
    })
    .then(res=>{
      console.log(res);
     if(res.data.data>0)
     {
      alert("删除成功");
      BorrowList();
     }
     else{
      alert("删除失败");
      return;
     }
    })
    .catch(err=>{
      console.log(err);
    })
  }
}
function Upd()
{
  router.push("/update")
}
</script>

<style scoped></style>
